package com.example.yunhailutong.zhongtan.net.base;

import android.text.TextUtils;

import com.android.volley.AuthFailureError;
import com.android.volley.Response;
import com.android.volley.toolbox.StringRequest;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2016/5/23 0023.
 */
public class iStringRequest extends StringRequest {

    private Map<String, String> params = new HashMap<>();
    private Map<String, String> params1 = new HashMap<>();
    private Map<String, String> header = new HashMap<>();

    public iStringRequest(int method, String url, Response.Listener<String> listener, Response.ErrorListener errorListener) {
        super(method, url, listener, errorListener);
    }

    public iStringRequest(String url, Response.Listener<String> listener, Response.ErrorListener errorListener) {
        super(url, listener, errorListener);

    }

    @Override
    public Map<String, String> getHeaders() throws AuthFailureError {
        return header;
    }

    @Override
    protected Map<String, String> getParams() throws AuthFailureError {
        return params;
    }

    public iStringRequest addParams(String key, String valse) {
        if (TextUtils.isEmpty(key))
            throw new RuntimeException("iStringRequest addParams 中的 key 必须不能为空");
        params.put(key, valse);
        return this;
    }

    public iStringRequest addHeaders(String key, String valse) {
        if (TextUtils.isEmpty(key) || TextUtils.isEmpty(valse))
            throw new RuntimeException("iStringRequest addHeaders 中的 key valse 必须不能为空");
        header.put(key, valse);
        return this;
    }

    public iStringRequest addHeaders(Map<String, String> headers) {
        this.header = headers;
        return this;
    }

    public iStringRequest addParams(Map<String, String> params) {
        this.params = params;
        return this;
    }

    @Override
    public byte[] getBody() throws AuthFailureError {
        return super.getBody();
    }
}
